package com.sino.cloud.api.domain;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;

public class Tag implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final Map<String, Object> vendorExtensions = new HashMap<String, Object>();
	private String name;
	private String description;
	private ExternalDocs externalDocs;

	public Tag name(String name) {
		setName(name);
		return this;
	}

	public Tag description(String description) {
		setDescription(description);
		return this;
	}

	public Tag externalDocs(ExternalDocs externalDocs) {
		setExternalDocs(externalDocs);
		return this;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public ExternalDocs getExternalDocs() {
		return externalDocs;
	}

	public void setExternalDocs(ExternalDocs externalDocs) {
		this.externalDocs = externalDocs;
	}

	@JsonAnyGetter
	public Map<String, Object> getVendorExtensions() {
		return vendorExtensions;
	}

	@JsonAnySetter
	public void setVendorExtension(String name, Object value) {
		if (name.startsWith("x-")) {
			vendorExtensions.put(name, value);
		}
	}

	@Override
	public String toString() {
		StringBuilder b = new StringBuilder();
		b.append("Tag {\n");
		b.append("\tname: ").append(getName()).append("\n");
		b.append("\tdescription: ").append(getDescription()).append("\n");
		b.append("\texternalDocs: ").append(getExternalDocs()).append("\n");
		b.append("\textensions:").append(vendorExtensions.toString());
		b.append("}");
		return b.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result
				+ ((externalDocs == null) ? 0 : externalDocs.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Tag other = (Tag) obj;
		if (description == null) {
			if (other.description != null) {
				return false;
			}
		} else if (!description.equals(other.description)) {
			return false;
		}
		if (externalDocs == null) {
			if (other.externalDocs != null) {
				return false;
			}
		} else if (!externalDocs.equals(other.externalDocs)) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		return true;
	}
}